#include <catch2/catch.hpp>

#include "solution.hpp"

using namespace solution_049;

TEST_CASE("049_group_anagrams", "[049]") {
    SECTION("example 1") {
        auto strs = std::vector<std::string>{"eat","tea","tan","ate","nat","bat"};
        auto grps = Solution().groupAnagrams(strs);
        for (auto& grp : grps)
            std::sort(grp.begin(), grp.end());
        std::sort(grps.begin(), grps.end(), [](auto& lhs, auto& rhs) { return lhs.size() < rhs.size(); });
        CHECK(grps == std::vector< std::vector<std::string> >{{"bat"},{"nat","tan"},{"ate","eat","tea"}});
    }

    SECTION("example 2") {
        auto strs = std::vector<std::string>{""};
        auto grps = Solution().groupAnagrams(strs);
        CHECK(grps == std::vector< std::vector<std::string> >{{""}});
    }

    SECTION("example 3") {
        auto strs = std::vector<std::string>{"a"};
        auto grps = Solution().groupAnagrams(strs);
        CHECK(grps == std::vector< std::vector<std::string> >{{"a"}});
    }
}
